//----------------------------------Include-------------------------------------
#include <stdio.h>
#include <string.h>
#include <stdint.h>

#include "glbvar.h"
#include "mcu.h"
#include "board.h"
#include "key.h"
#include "eth.h"
//------------------------------------------------------------------------------

//-----------------------------------Macro--------------------------------------
//------------------------------------------------------------------------------

//---------------------------------Static Var-----------------------------------
char txbuf[256];
//------------------------------------------------------------------------------
float    temp;
uint8_t  res;
//------------------------------------------------------------------------------

//--------------------------------Static Func-----------------------------------
static void _welcome(void)
{
  mcu_lcd_beep(1);
  mcu_lcd_led1(1);
  mcu_lcd_led2(1);
  mcu_lcd_led3(1);
  mcu_lcd_led4(1);
  mcu_lcd_led5(1);
  mcu_delay_ms(500);
  mcu_lcd_beep(0);
  mcu_lcd_led1(0);
  mcu_lcd_led2(0);
  mcu_lcd_led3(0);
  mcu_lcd_led4(0);
  mcu_lcd_led5(0);
  
  mcu_relay1(1);  mcu_delay_ms(500);
  mcu_relay1(0);  mcu_delay_ms(500);
  mcu_relay2(1);  mcu_delay_ms(500);
  mcu_relay2(0);  mcu_delay_ms(500);
  mcu_cat1_en(1);
}
//------------------------------------------------------------------------------

//--------------------------------Public Func-----------------------------------
int main(void)
{
  brd_init();
  key_init();
  
  _welcome();
  
  brd_init_lcd();
  brd_LcdDrv_FillRect(0, 0, 320, 240, BLACK);
  mcu_lcd_backlight(1);
  
  mcu_delay_ms(1000);
  brd_LcdDrv_FillRect(0, 0, 300, 200, RED);
  
  //eth_init();
  while(1){
    temp  = mcu_get_temp();
    sprintf(txbuf, "T:%0.2f\r\n", temp);
    //mcu_uart6_dma_tx(txbuf, strlen(txbuf));
    mcu_uart7_dma_tx(txbuf, strlen(txbuf));
    mcu_delay_ms(1000);
    
    mcu_delay_ms(1000);
    brd_LcdDrv_FillRect(0, 0, 320, 240, CYAN);
    mcu_delay_ms(1000);
    brd_LcdDrv_FillRect(0, 0, 320, 240, YELLOW);
    
    //Delay_Us(3);
    //mcu_test_toggle();
    //Delay_Us(3);
    //mcu_test_toggle();
    
    //eth_cyc();
  }
  
  return 0;
}
//------------------------------------EOF---------------------------------------

//uint8_t eewbuf[20];
//uint8_t eerbuf[1024];
//sprintf((char*)eewbuf, "hello,world!eepromok");
//brd_24c256_wr_n_byte(2048-40, eewbuf, 20);
//brd_24c256_rd_n_byte(0, eerbuf, 2048);

